define(()=>{
    return function(nav_span) {
        'use strict';
        class Guard{
            constructor(ops){
                this.nav_span = ops.nav_span
                this.dropOut = ops.dropOut;
                this.render();
                this.addEvent();
            }
            render(){
                if(localStorage.getItem("isLogin") === "YES"){
                    this.nav_span.innerHTML = `<a href="./personal.html" style="color:#1e1e1e;">${localStorage.getItem("username")}&nbsp; 新华伴您畅游书海。</a>
                                                <a href="./index.html" class="dropOut">退出登录</a>`;
                }else{
                    this.nav_span.innerHTML = `<a href="./login.html">请登录</a>
                                                <a href="./registered.html">免费注册</a>`;
                }
            }
            addEvent(){
                this.nav_span.addEventListener("click",(eve)=>{
                    const e = eve || window.event;
                    const target = e.target || e.srcElement || e.toElement;
                    if(target.className === "dropOut"){
                        localStorage.setItem("isLogin","");
                    }
                })
            }
        }
        new Guard({
            nav_span:nav_span,
            dropOut:document.querySelector(".dropOut")
        });
    }
    
});